package service

import (
	"fmt"
	"im-tools/internal/model"
	"im-tools/pkg"

	"github.com/fatih/color"
)

type FriendService struct {
}

func (fs *FriendService) AddOneFriend(uid, friendId string) {
	var friendModel = &model.FriendModel{
		UserUid:       uid,
		FriendUserUid: friendId,
	}
	if err := pkg.MysqlDB.Model(friendModel).Create(friendModel).Error; err != nil {
		fmt.Printf("color.Error: %v\n", color.Error)
	}
}

// 给当前登录用户添加一定数量的好友
func (fs *FriendService) AddFriends(ownerUid string, num int) {

	us := &UserService{}
	users := us.SelectUsers(num)

	var friends = []model.FriendModel{}
	for _, u := range users {
		friends = append(friends, model.FriendModel{
			UserUid:       ownerUid,
			FriendUserUid: u.FakeUid,
		})
	}

	if err := pkg.MysqlDB.Create(&friends).Error; err != nil {
		fmt.Printf("color.Error: %v\n", color.Error)
	}

}
